var gltUtils = {};
// 设备判断
gltUtils.device = function () {
  try {
    if (/iPhone/i.test(navigator.userAgent)) {
      return "2";
    }
    else if (/webOS|iPod|BlackBerry/i.test(navigator.userAgent)) {
      return "4";
    }
    else if (/Android/i.test(navigator.userAgent)) {
      return "3";
    }
    else if (navigator.userAgent.indexOf("Windows Phone") > -1) {
      return "5";
    }
    else {
      // pc
      return "1";
    }
  }
  catch (e) {
    return "0";
  }
};
// 所有字符串替换
String.prototype.replaceAll = function(s1, s2){
  return this.replace(new RegExp(s1, "gm"), s2);
};
// number类型计数转换
Number.prototype.computeUnit = function(type){
  let _this = this;
  let num;
  let unit,unitRange;
  let symbol = "";
  if(this < 0){
    symbol = "-";
    _this = Math.abs(this);
  }
  if(type === "万"){
    if(_this > 10000){
      unitRange = 10000;
      // unit = "万";
      num = symbol + (Math.round((_this / unitRange) * 100) / 100)
    }else{
      num = symbol + _this
    }
  }else{
    if(_this > 100000000){
      unitRange = 100000000;
      unit = "亿";
      num = symbol + (Math.round((_this / unitRange) * 100) / 100) + unit
    }else if(_this > 10000){
      unitRange = 10000;
      unit = "万";
      num = symbol + (Math.round((_this / unitRange) * 100) / 100) + unit
    }else{
      num = symbol + _this
    }
  }
  return num;
};
// number类型添加百分号
Number.prototype.addPercent = function(){
  return this + '%';
};
//  实现siblings方法
gltUtils.siblingEl = function(el){
  var nodes = [];
  var _el = el;
  while((el = el.previousSibling)){
    if(el.nodeType === 1){
      nodes.push(el);
    }
  }
  var el = _el;
  while((el = el.nextSibling)){
    if(el.nodeType === 1){
      nodes.push(el);
    }
  }
  return nodes;

};
// 确认对应颜色
gltUtils.compareNumber = function(number){
  if(number > 0 ){
    return "colorRed";
  }else if(number < 0 ){
    return "colorGreen";
  }else{
    return "colorGray";
  }
};
export default gltUtils;
